package com.tzy.myfootprint.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tzy.common.entity.MyFootprint;
import com.tzy.myfootprint.mapper.MyFootprintMapper;
import com.tzy.myfootprint.service.IMyFootprintService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 我的足迹表 服务实现类
 * </p>
 *
 * @author ljh
 * @since 2022-03-13
 */
@Service
public class MyFootprintService extends ServiceImpl<MyFootprintMapper, MyFootprint> implements IMyFootprintService {

	private Logger log = LoggerFactory.getLogger("FootprintServeice");

	@Resource
	private MyFootprintMapper myFootprintMapper;

	@Override
	public boolean addFootprint(MyFootprint footprint) {
		int count = myFootprintMapper.insert(footprint);
		if(count >= 1){
			return true;
		}
		return false;
	}

	@Override
	public List<MyFootprint> listFootprint(int userId) {
		List<MyFootprint> list = myFootprintMapper.listFootprint(userId);
		return list;
	}

	@Override
	public boolean countFootprint(MyFootprint myFootprint) {
		QueryWrapper<MyFootprint> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("user_id", myFootprint.getUserId())
				.eq("shop_id", myFootprint.getShopId());
		MyFootprint myFootprint1 = myFootprintMapper.selectOne(queryWrapper);
		//当前系统时间

		LocalDateTime dateTime = LocalDateTime.now();
		log.info("当前系统时间："+dateTime);
		if(myFootprint1 != null){
			myFootprint1.setFootprintTime(dateTime);
			log.info("footprint:"+myFootprint.toString());
			int size = myFootprintMapper.updateById(myFootprint1);
			log.info("修改用户当前店铺足迹时间:");
			if(size > 0){
				log.info("成功！");
			}else{
				log.info("失败！");
			}
			return false;
		}
		return true;
	}

	@Override
	public boolean deleteFootprint(int userId, Integer[] shopId) {
		int count = myFootprintMapper.deleteFootprint(userId,shopId);
		log.info("delete count:"+count);
		if(count >0){
			return true;
		}
		return false;
	}
}
